<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script type="text/javascript" src="JS/jquery-3.3.1.js"></script>
    <style type="text/css">
    div{
        width: 400px;
        margin: 10px;
    }
    #btnOK,#btnValue{
        width: 150px;
        height: 30px;
        line-height: 30px;
        margin-right: 10px;
        background-color: #11c3cf;
        color: #ffffff;
    }
    </style>
    <script type="text/javascript">
    $(function(){
        $("#btnOK").click(function(){
            $("[name=sports]:checkbox").each(function(){
                this.checked=!this.checked;
            });
        });

        $("#btnValue").click(function(){
            var _Str = "";
            $("[name=sports]:checkbox").each(function(){
                if($(this).is(":checked")){
                    _Str+=$(this).val()+"  ";
                }
            });
            alert(_Str);
        });
    });
    </script>
</head>
<body>
    <div>
        <input id="btnOK" type="button" value="全选">
        <input id="btnValue" type="button" value="获取选择项目的值">
    </div>
    <div>
        <input name="sports" type="checkbox" value="足球">足球
        <input name="sports" type="checkbox" value="篮球">篮球
        <input name="sports" type="checkbox" value="排球">排球
        <input name="sports" type="checkbox" value="羽毛球">羽毛球
        <input name="sports" type="checkbox" value="乒乓球">乒乓球
    </div>
</body>
</html>